package utils

import (
	"fmt"
	"github.com/jordan-wright/email"
	"log"
	"net/smtp"
	"time"
)

const maxConn int = 10

// 邮箱基本配置
const (
	nickName string = "rabbitLove"
	address  string = "2624234818@qq.com"
	secret   string = "fpldpsnihalqdhfi"
	//address string = "1439441462@qq.com"
	//secret  string = "aeepobhbcoahhjja"
	host string = "smtp.qq.com"
	port int    = 587
)

var (
	EmailPool *email.Pool
)

func SendEmailWithPool(to []string, subject, body string) (err error) {
	hostAddr := fmt.Sprintf("%s:%d", host, port)
	auth := smtp.PlainAuth("", address, secret, host)
	if EmailPool == nil {
		EmailPool, err = email.NewPool(hostAddr, maxConn, auth)
		if err != nil {
			log.Fatal(err)
		}
	}
	e := &email.Email{
		From:    fmt.Sprintf("%s<%s>", nickName, address),
		To:      to,
		Subject: subject,
		Text:    []byte(body),
	}
	return EmailPool.Send(e, 5*time.Second)
}

var (
	RegisterCode      string = "欢迎您注册情侣互联！您的验证码是：%s。验证码的有效时长是10分钟，亲尽快使用。"
	ForgetCode        string = "您的验证码是：%s。验证码的有效时长是10分钟，亲尽快使用。"
	InviteLoverNotify string = "%s刚才邀请您作为对方的恋人，您不在的这段时间，被%d人所邀请。"
)
